package view;

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import swingComponents.MyCellEditor;
import swingComponents.MyCheckBox;
import swingComponents.MyTableCellRenderer;
import utils.JsonUtils;
import utils.StringUtils;
import dto.KeyValueModel;
import dto.Passenger;
import java.awt.Font;

public class ReserveView extends BaseView implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel randCode_label;
	private JTextField randCode_text;
	private Image image;

	private String token;
	private String leftTicketStr;
	private String purpose_codes;
	private String train_location;
	private String key_check_isChange;
	private JSONObject orderRequestDTO;
	private String station_train_code;
	private String fromStationTelecode;
	private String toStationTelecode;
	private String train_no;
	private String leftDetails;
	private String[] ticketsAndPrices;
	private KeyValueModel[] ticketTypes;
	private KeyValueModel[] seatTypes;
	private KeyValueModel[] cardTypes;
	private JTable table;

	private int passenger_index = 1;
	private MyCheckBox[] myCheckBoxes;
	private JLabel trainNumLabel;
	private JLabel trainNumLabel2;
	private JLabel startTimeLabel;
	private JButton btnRefresh;

	// data
	private JSONObject train;

	public ReserveView(JSONObject train) throws Exception {
		this.train = train;
		init();
	}

	private void init() throws IllegalArgumentException, IllegalAccessException {
		// 初始化单程页面
		initDc();

		JPanel topPanel = new JPanel();
		topPanel.setPreferredSize(new Dimension(10, 100));
		getContentPane().add(topPanel, BorderLayout.NORTH);
		topPanel.setLayout(new BorderLayout(0, 0));

		JPanel topPanel2 = new JPanel();
		topPanel2.setPreferredSize(new Dimension(10, 60));
		topPanel.add(topPanel2, BorderLayout.NORTH);
		topPanel2.setLayout(new BorderLayout(0, 0));

		JPanel ticketsPanel = new JPanel();
		ticketsPanel.setFont(new Font("SimSun", Font.BOLD, 12));
		ticketsPanel.setPreferredSize(new Dimension(10, 30));
		topPanel2.add(ticketsPanel, BorderLayout.NORTH);

		JLabel label = new JLabel("余票信息：");
		label.setForeground(Color.RED);
		label.setFont(new Font("SimSun", Font.BOLD, 16));
		ticketsPanel.add(label);

		JLabel lblNewLabel = new JLabel(leftDetails);
		ticketsPanel.add(lblNewLabel);

		JPanel trainInfoPanel = new JPanel();
		topPanel2.add(trainInfoPanel, BorderLayout.CENTER);

		this.trainNumLabel = new JLabel("车次：");
		this.trainNumLabel.setForeground(Color.RED);
		trainInfoPanel.add(this.trainNumLabel);

		this.trainNumLabel2 = new JLabel(train.getString("station_train_code"));
		trainInfoPanel.add(this.trainNumLabel2);

		JLabel fromStationLabel = new JLabel("出发：");
		fromStationLabel.setForeground(Color.RED);
		trainInfoPanel.add(fromStationLabel);

		JLabel fromStationLabel2 = new JLabel(train
				.getString("from_station_name"));
		trainInfoPanel.add(fromStationLabel2);

		JLabel toStationLabel = new JLabel("到达：");
		toStationLabel.setForeground(Color.RED);
		trainInfoPanel.add(toStationLabel);

		JLabel toStationLabel2 = new JLabel(train.getString("to_station_name"));
		trainInfoPanel.add(toStationLabel2);

		this.startTimeLabel = new JLabel("出发时间：");
		this.startTimeLabel.setForeground(Color.RED);
		trainInfoPanel.add(this.startTimeLabel);

		JLabel startTimeLabel2 = new JLabel(train.getString("start_time"));
		trainInfoPanel.add(startTimeLabel2);

		JLabel endTimeLabel = new JLabel("到达时间");
		endTimeLabel.setForeground(Color.RED);
		trainInfoPanel.add(endTimeLabel);

		JLabel endTimeLabel2 = new JLabel(train.getString("arrive_time"));
		trainInfoPanel.add(endTimeLabel2);

		JLabel lishiLabel = new JLabel("历时");
		lishiLabel.setForeground(Color.RED);
		trainInfoPanel.add(lishiLabel);

		JLabel lishiLabel2 = new JLabel(train.getString("lishi"));
		trainInfoPanel.add(lishiLabel2);

		JPanel peoplePanel = new JPanel();
		topPanel.add(peoplePanel, BorderLayout.CENTER);

		JPanel bottomPanel = new JPanel();
		bottomPanel.setPreferredSize(new Dimension(10, 450));
		getContentPane().add(bottomPanel, BorderLayout.SOUTH);
		bottomPanel.setLayout(new BorderLayout(0, 0));

		JPanel buttonPanel = new JPanel();
		buttonPanel.setPreferredSize(new Dimension(10, 100));
		bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
		buttonPanel.setLayout(null);

		JButton btnNewButton = new JButton("确定");
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				String resInfo = "";
				Map<?, ?> resMap = null;
				String oldPassengerStr = "";
				String passengerTicketStr = "";
				// DefaultTableModel tableModel = (DefaultTableModel) table
				// .getModel();
				// int rowCount = tableModel.getRowCount();
				// 在表格中的数据也就是多选框中选中的!
				for (int i = 0; i < myCheckBoxes.length; i++) {
					if (myCheckBoxes[i].isSelected()) {
						Passenger passenger = myCheckBoxes[i].getPassenger();
						/**
						 * oldPassengersStr也是以下划线"_"分隔每个乘客信息组成的字符串
						 * 对应每个乘客信息字符串组成如下: 乘客名,证件类型,证件号,乘客类型
						 */
						oldPassengerStr += passenger.getPassenger_name() + ","
								+ passenger.getPassenger_id_type_code() + ","
								+ passenger.getPassenger_id_no() + ","
								+ passenger.getPassenger_type() + "_";
						/**
						 * passengerTicketStr是以下划线"_"分隔当每一个乘客信息组成的字符串
						 * 座位编号,0,票类型,乘客名,证件类型,证件号,手机号码,保存常用联系人(Y或N)
						 */
						passengerTicketStr += "_" + passenger.getSeat_type_id()
								+ ",0" + "," + passenger.getPassenger_type()
								+ "," + passenger.getPassenger_name() + ","
								+ passenger.getPassenger_id_type_code() + ","
								+ passenger.getPassenger_id_no() + ","
								+ passenger.getMobile_no() + ",N";
					}
				}
				passengerTicketStr = passengerTicketStr.substring(1);
				System.out.println("oldPassengerStr = " + oldPassengerStr);
				System.out
						.println("passengerTicketStr = " + passengerTicketStr);
				resInfo = checkRandCodeAnsyn(randCode_text.getText());
				resMap = JsonUtils.getDataMap(resInfo);
				if (resMap.get("status").equals("false")) {
					JOptionPane.showMessageDialog(ReserveView.this,
							StringUtils.isNotBlank(resMap.get("messages")
									.toString()) ? resMap.get("messages")
									.toString() : "验证码输入有误");
					return;
				}
				resInfo = checkOrderInfo(oldPassengerStr, passengerTicketStr);
				System.out.println(resInfo);
				resMap = JsonUtils.getDataMap(resInfo);
				if (resMap.get("status").equals("false")) {
					JOptionPane.showMessageDialog(ReserveView.this,
							StringUtils.isNotBlank(resMap.get("messages")
									.toString()) ? resMap.get("messages")
									.toString() : "乘客信息有误");
					return;
				}
				if (resMap.get("submitStatus").equals("false")) {
					JOptionPane.showMessageDialog(ReserveView.this,
							StringUtils.isNotBlank(resMap.get("errMsg")
									.toString()) ? resMap.get("errMsg")
									.toString() : "乘客信息有误");
					return;
				}
				getQueueCount();
				resInfo = confirmSingleForQueue(oldPassengerStr,
						passengerTicketStr, randCode_text.getText());
				System.out.println(resInfo);
				resMap = JsonUtils.getDataMap(resInfo);
				if (resMap.get("submitStatus").equals("false")) {
					JOptionPane.showMessageDialog(ReserveView.this,
							StringUtils.isNotBlank(resMap.get("errMsg")
									.toString()) ? resMap.get("errMsg")
									.toString() : "乘客信息有误");
					return;
				}
				JOptionPane.showMessageDialog(ReserveView.this,
						"预定成功，<a>点击前往12306查看已预定的票</a>");
			}
		});
		btnNewButton.setBounds(457, 34, 93, 28);
		buttonPanel.add(btnNewButton);

		JButton button = new JButton("清空");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DefaultTableModel model = (DefaultTableModel) table.getModel();
				model.setRowCount(0);
				// 还要把多选框的按钮全部去选
				for (int i = 0; i < myCheckBoxes.length; i++) {
					myCheckBoxes[i].setSelected(false);
				}
			}
		});
		button.setBounds(588, 34, 93, 28);
		buttonPanel.add(button);

		// 验证码 (要是用异步加载就好了) 已完成
		randCode_label = new JLabel();
		new SyncLoader().execute();
		randCode_text = new JTextField();
		randCode_text.setBounds(293, 38, 66, 21);
		buttonPanel.add(randCode_text);

		randCode_label.setBounds(73, 41, 78, 26);
		buttonPanel.add(randCode_label);

		JButton btnNewButton_1 = new JButton("看不清楚");
		btnNewButton_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				getRandCode();
			}
		});
		btnNewButton_1.setBounds(174, 37, 93, 23);
		buttonPanel.add(btnNewButton_1);

		this.btnRefresh = new JButton("refresh");
		this.btnRefresh.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_btnRefresh_actionPerformed(e);
			}
		});
		this.btnRefresh.setBounds(527, 72, 93, 23);
		buttonPanel.add(this.btnRefresh);

		JPanel tablePanel = new JPanel();
		bottomPanel.add(tablePanel, BorderLayout.CENTER);
		tablePanel.setLayout(null);

		// 得到常用联系人信息
		String resInfo = controller.getPassengerDTOs(
				"https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs",
				null);
		JSONObject jsonObject = JSONObject.fromObject(resInfo);
		JSONObject personObject = jsonObject.getJSONObject("data");
		JSONArray personArr = personObject.getJSONArray("normal_passengers");
		int personLen = personArr.size();

		// 选中的联系人信息
		// 构造表格
		String[] headers = { "序号", "席别", "票种", "姓名", "证件类型", "证件号码", "手机号码",
				"删除" };
		DefaultTableModel model = new DefaultTableModel(null, headers) {
			@Override
			public boolean isCellEditable(int row, int column) {
				if (column == 0) {
					return false;
				}
				return true;
			}

			@Override
			public Class<?> getColumnClass(int columnIndex) {
				Vector vector = (Vector) dataVector.get(0);
				if (vector.get(columnIndex) != null) {
					return vector.get(columnIndex).getClass();
				}
				return Object.class;
			}
		};
		table = new JTable(model);
		// 设置列宽
		table.getColumnModel().getColumn(0).setPreferredWidth(30);
		table.getColumnModel().getColumn(1).setPreferredWidth(130); // 票种
		table.getColumnModel().getColumn(3).setPreferredWidth(60); // 姓名
		table.getColumnModel().getColumn(4).setPreferredWidth(100); // 证件类型
		table.getColumnModel().getColumn(5).setPreferredWidth(140); // 证件号码
		table.getColumnModel().getColumn(6).setPreferredWidth(90); // 手机号码
		// 设置列高
		table.setRowHeight(25);
		table.setDefaultRenderer(JComboBox.class, new MyTableCellRenderer());
		table.setDefaultEditor(JComboBox.class, new MyCellEditor());
		JScrollPane scrollPane = new JScrollPane(table);
		scrollPane.setBounds(10, 15, 750, 320);
		scrollPane.setPreferredSize(new Dimension(750, 320));
		tablePanel.add(scrollPane);

		myCheckBoxes = new MyCheckBox[personLen];
		for (int j = 0; j < personLen; j++) {
			final int jj = j;
			JSONObject person = personArr.getJSONObject(j);
			myCheckBoxes[j] = new MyCheckBox(person.getString("passenger_name"));
			// 填充数据到checkBox
			Passenger passenger = new Passenger();
			fillData(passenger, person);
			myCheckBoxes[j].setPassenger(passenger);
			myCheckBoxes[j].addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					// 把数据塞到table中去
					DefaultTableModel tableModel = (DefaultTableModel) table
							.getModel();
					Passenger passenger = myCheckBoxes[jj].getPassenger();
					if (myCheckBoxes[jj].isSelected()) {
						// 填充数据
						Object[] arr = new Object[7];
						arr[0] = String.valueOf(passenger_index++); // 序号
						arr[1] = new JComboBox(seatTypes);// 席别
						JComboBox jComboBox = (JComboBox) arr[1];
						KeyValueModel model = (KeyValueModel) jComboBox
								.getSelectedItem();
						passenger.setSeat_type_id(model.getKey());
						jComboBox.setActionCommand("seatTypes" + ","
								+ String.valueOf(jj));
						jComboBox.addActionListener(ReserveView.this);
						arr[2] = new JComboBox(ticketTypes); // 票种 TODO
						jComboBox = (JComboBox) arr[2];
						model = (KeyValueModel) jComboBox.getSelectedItem();
						passenger.setPassenger_type(model.getKey());
						jComboBox.setActionCommand("ticketType" + ","
								+ String.valueOf(jj));
						jComboBox.addActionListener(ReserveView.this);
						arr[3] = passenger.getPassenger_name(); // 姓名
						arr[4] = new JComboBox(cardTypes); // 证件类型
						jComboBox = (JComboBox) arr[4];
						model = (KeyValueModel) jComboBox.getSelectedItem();
						passenger.setPassenger_id_type_code(model.getKey());
						jComboBox.setActionCommand("cardTypes" + ","
								+ String.valueOf(jj));
						jComboBox.addActionListener(ReserveView.this);
						arr[5] = passenger.getPassenger_id_no(); // 证件号码
						arr[6] = passenger.getMobile_no(); // 手机号码

						// 添加数据到表格
						tableModel.addRow(arr);

						// 更新表格
						table.invalidate();
					} else {
						// 去除这一行 TODO
					}
				}
			});
			peoplePanel.add(myCheckBoxes[j]);
		}

		// 从选定的人中得到数据

		setSize(800, 600);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

	}

	/**
	 * 初始化预订页面(Dc为单程订票界面) 并得到关键数据 TODO 也要异步实现了
	 */
	private void initDc() {
		String content = controller.initDc(
				"https://kyfw.12306.cn/otn/confirmPassenger/initDc", null);
		JSONArray jsonArray = JSONArray.fromObject(JsonUtils.getVarFromJs(
				content, "init_cardTypes"));
		int len = jsonArray.size();
		cardTypes = new KeyValueModel[len];
		for (int i = 0; i < len; i++) {
			JSONObject jsonObject = (JSONObject) jsonArray.get(i);
			cardTypes[i] = new KeyValueModel();
			cardTypes[i].setKey(jsonObject.getString("id"));
			cardTypes[i].setValue(jsonObject.getString("value"));
		}
		jsonArray = JSONArray.fromObject(JsonUtils.getVarFromJs(content,
				"defaultTicketTypes"));
		len = jsonArray.size();
		ticketTypes = new KeyValueModel[len];
		for (int i = 0; i < len; i++) {
			JSONObject jsonObject = (JSONObject) jsonArray.get(i);
			ticketTypes[i] = new KeyValueModel();
			ticketTypes[i].setKey(jsonObject.getString("id"));
			ticketTypes[i].setValue(jsonObject.getString("value"));
		}
		jsonArray = JSONArray.fromObject(JsonUtils.getVarFromJs(content,
				"init_seatTypes"));
		len = jsonArray.size();
		seatTypes = new KeyValueModel[len];
		for (int i = 0; i < len; i++) {
			JSONObject jsonObject = (JSONObject) jsonArray.get(i);
			seatTypes[i] = new KeyValueModel();
			seatTypes[i].setKey(jsonObject.getString("id"));
			seatTypes[i].setValue(jsonObject.getString("value"));
		}
		token = controller.extractToken("globalRepeatSubmitToken", content, 1);
		token = token.replaceAll("'", "");
		String ticketInfoForPassengerForm = controller.extractToken(
				"ticketInfoForPassengerForm", content, 2);
		JSONObject jsonObject = JSONObject
				.fromObject(ticketInfoForPassengerForm);
		leftTicketStr = jsonObject.getString("leftTicketStr");
		purpose_codes = jsonObject.getString("purpose_codes");
		train_location = jsonObject.getString("train_location");
		key_check_isChange = jsonObject.getString("key_check_isChange");
		orderRequestDTO = jsonObject.getJSONObject("orderRequestDTO");
		station_train_code = orderRequestDTO.getString("station_train_code");
		fromStationTelecode = orderRequestDTO
				.getString("from_station_telecode");
		toStationTelecode = orderRequestDTO.getString("to_station_telecode");
		train_no = orderRequestDTO.getString("train_no");
		// 得到另外的信息(下拉列表数据构造)

		// 得到剩余的票的种类和票价
		leftDetails = jsonObject.getString("leftDetails");
		leftDetails = StringUtils.getFromBracket(leftDetails, "[");
		leftDetails = leftDetails.replaceAll("\"", "");
		// String[] s = leftDetails.split("\\(|,|\\)");
		// List<LeftTickets> leftTicketsList = new ArrayList<LeftTickets>();
		// for (String string : s) {
		// LeftTickets leftTickets = new LeftTickets();
		// leftTickets.setSeat_type_name(string);
		// }

		// 剔除无票的情况
		String[] tempTicketsAndPrices = leftDetails.split(",");
		int count = 0;
		for (int i = 0; i < tempTicketsAndPrices.length; i++) {
			if (tempTicketsAndPrices[i].substring(0, 2).equals("无座")
					|| tempTicketsAndPrices[i].substring(
							tempTicketsAndPrices[i].length() - 2).equals("无票")) {
				tempTicketsAndPrices[i] = "";
			} else {
				count++;
			}
		}
		ticketsAndPrices = new String[count];
		for (int i = 0, index = 0; i < tempTicketsAndPrices.length; i++) {
			if (StringUtils.isNotEmpty(tempTicketsAndPrices[i])) {
				ticketsAndPrices[index++] = tempTicketsAndPrices[i].substring(
						0, tempTicketsAndPrices[i].lastIndexOf(")") + 1);
			}
		}
	}

	private void getRandCode() {
		image = controller
				.getRandCode("https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp");
		randCode_label.setIcon(new ImageIcon(image));
	}

	private void fillData(Passenger passenger, JSONObject json)
			throws IllegalArgumentException, IllegalAccessException {
		Class<?> clazz = passenger.getClass();
		Field[] fields = clazz.getDeclaredFields();
		String fieldName = "";
		for (Field field : fields) {
			fieldName = field.getName();
			if (json.containsKey(fieldName)) {
				field.setAccessible(true);
				field.set(passenger, json.getString(fieldName));
			}
		}
	}

	private String checkRandCodeAnsyn(String randCode) {
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("REPEAT_SUBMIT_TOKEN", token));
		nvps.add(new BasicNameValuePair("rand", "randp"));
		nvps.add(new BasicNameValuePair("randCode", randCode));
		return controller.checkRandCodeAnsyn(
				"https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn",
				nvps);
	}

	private String checkOrderInfo(String oldPassengerStr,
			String passengerTicketStr) {
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("cancel_flag", "2"));
		nvps.add(new BasicNameValuePair("REPEAT_SUBMIT_TOKEN", token));
		nvps.add(new BasicNameValuePair("bed_level_order_num",
				"000000000000000000000000000000"));
		nvps.add(new BasicNameValuePair("oldPassengerStr", oldPassengerStr));
		nvps.add(new BasicNameValuePair("passengerTicketStr",
				passengerTicketStr));
		nvps.add(new BasicNameValuePair("randCode", randCode_text.getText()));
		nvps.add(new BasicNameValuePair("tour_flag", "dc"));
		String resInfo = controller.checkOrderInfo(
				"https://kyfw.12306.cn/otn/confirmPassenger/checkOrderInfo",
				nvps);
		return resInfo;
	}

	private String getQueueCount() {
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("REPEAT_SUBMIT_TOKEN", token));
		nvps.add(new BasicNameValuePair("fromStationTelecode",
				fromStationTelecode));
		nvps.add(new BasicNameValuePair("leftTicket", leftTicketStr));
		nvps.add(new BasicNameValuePair("purpose_codes", purpose_codes));
		nvps.add(new BasicNameValuePair("seatType", "0")); // TODO
		nvps
				.add(new BasicNameValuePair("stationTrainCode",
						station_train_code));
		nvps
				.add(new BasicNameValuePair("toStationTelecode",
						toStationTelecode));
		nvps.add(new BasicNameValuePair("train_date",
				"Mon Mar 31 2014 00:00:00 GMT+0800")); // TODO 貌似没有用
		nvps.add(new BasicNameValuePair("train_no", train_no));
		return controller.getQueueCount(
				"https://kyfw.12306.cn/otn/confirmPassenger/getQueueCount",
				nvps);
	}

	private String confirmSingleForQueue(String oldPassengerStr,
			String passengerTicketStr, String randCode) {
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("REPEAT_SUBMIT_TOKEN", token));
		nvps.add(new BasicNameValuePair("key_check_isChange",
				key_check_isChange));
		nvps.add(new BasicNameValuePair("leftTicketStr", leftTicketStr));
		nvps.add(new BasicNameValuePair("oldPassengerStr", oldPassengerStr));
		nvps.add(new BasicNameValuePair("passengerTicketStr",
				passengerTicketStr));
		nvps.add(new BasicNameValuePair("purpose_codes", purpose_codes));
		nvps.add(new BasicNameValuePair("randCode", randCode));
		nvps.add(new BasicNameValuePair("train_location", train_location));
		return controller
				.confirmSingleForQueue(
						"https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue",
						nvps);
	}

	private class SyncLoader extends SwingWorker<Object, Object> {

		@Override
		protected Object doInBackground() throws Exception {
			getRandCode();
			return null;
		}

	}

	protected void do_btnRefresh_actionPerformed(ActionEvent e) {
		getContentPane().removeAll();
		try {
			init();
		} catch (IllegalArgumentException e1) {
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String[] strs = e.getActionCommand().split(",");
		String actionCommand = strs[0];
		int i = Integer.parseInt(strs[1]);
		MyCheckBox checkBox = myCheckBoxes[i];
		Passenger passenger = checkBox.getPassenger();
		JComboBox box = (JComboBox) e.getSource();
		KeyValueModel model = (KeyValueModel) box.getSelectedItem();
		if (actionCommand.equals("seatTypes")) {
			passenger.setSeat_type_id(model.getKey());
		} else if (actionCommand.equals("cardTypes")) {
			passenger.setPassenger_id_type_code(model.getKey());
		} else if (actionCommand.equals("ticketTypes")) {
			passenger.setPassenger_type(model.getKey());
		}
	}
}
